package com.warwithinme.android.widgetwar;

import android.appwidget.AppWidgetManager;
import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceActivity;


public class WidgetPrefActivity extends PreferenceActivity
{

	private int mAppWidgetId;
	@Override
    protected void onCreate(Bundle savedInstanceState)
    {
		Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
        }

        // If they gave us an intent without the widget id, just bail.
        if (mAppWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) {
            finish();
        }
		Intent resultValue = new Intent();
        resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
		setResult(RESULT_OK, resultValue);
		super.onCreate(savedInstanceState);
	    addPreferencesFromResource(R.xml.widgetpref);
	   
    }

	@Override
    protected void onPause()
    {
		ToggleWidget toggleWidget = new ToggleWidget();
		AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
		toggleWidget.onUpdate(this, appWidgetManager, null);
	    super.onPause();        
    }
}
